package com.example.demo.Util;

import com.example.demo.Entity.Login;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class getToken {
    public static final String signnature = "wuyanfeng";
    public static final long EXPIRE = 1000*60*60*24;

    public String getTokens(Login login){
        JwtBuilder jwtBuilder= Jwts.builder();
        String jwtToken=jwtBuilder
                .setHeaderParam("typ","JWT")
                .setHeaderParam("alg","HS256")
                .claim("code",login.code)
                .claim("encryptedData",login.encryptedData)
                .claim("iv",login.iv)
                .claim("rawData",login.rawData)
                .setExpiration(new Date(System.currentTimeMillis()+EXPIRE))
                .signWith(SignatureAlgorithm.HS256,signnature)
                .compact();
        return jwtToken;
    }
}
